Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CreateTags instead of TagResources #129

Merged
merged 1 commit into from
Jul 16, 2018

Conversation

nckturner
Copy link
Contributor

@nckturner nckturner commented Jul 9, 2018

Issue #, if available:
Fixes: #76

Description of changes:

  • Switches to CreateTags instead of TagResources.
  • Also introduce two new tags:
    • node.k8s.amazonaws.com/instance_id
    • cluster.k8s.amazonaws.com/name (only tagged if the env var CLUSTER_NAME is present).

Testing:
Created an EKS cluster with a node, which was created with the current CNI. I checked the tag on the ENI, it was the old format. I then applied CNI yaml with a container I built and scaled in and out the autoscaling group to get new nodes. The first time I did this with CLUSTER_NAME set:

tag key tag value
cluster.k8s.amazonaws.com/name wonderful-outfit-1531613390
node.k8s.amazonaws.com/instance_id i-03eb4524c4c96774a

Second time without:

tag key tag value
node.k8s.amazonaws.com/instance_id i-0bf1f4f8e688b70fd

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Contributor

@liwenwu-amazon liwenwu-amazon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add how you test your changes? thanks

Copy link
Contributor

@vsiddharth vsiddharth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall changes look good. Left minor suggestions.

Could you please add some tests to validate the new changes?

package mock_ec2wrapper

import (
reflect "reflect"

"github.com/aws/aws-sdk-go/service/ec2"
ec2 "github.com/aws/aws-sdk-go/service/ec2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this autogenerated using a newer version of mockgen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it, due to the slight differences. It was generated with go generate ./pkg/awsutils/...

tags[eniTagKey] = aws.String(tagValue)
log.Debugf("Trying to tag newly created eni: keys=%s, value=%s", eniTagKey, tagValue)
for _, tag := range tags {
log.Debugf("Trying to tag newly created eni: key=%s, value=%s", *tag.Key, *tag.Value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use aws.StringValue here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

awsAPIErrInc("TagResources", err)
log.Warnf("Fail to tag the newly created eni %s %v", eniID, err)
awsAPIErrInc("CreateTags", err)
log.Warnf("Fail to tag the newly created eni %s: %v", eniID, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Fail/Failed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, done.

Resource: "network-interface/" + eniID}
arnString := eniARN.String()
arns = append(arns, aws.String(arnString))
tags := []*ec2.Tag{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment with the sample tag keys and values for an ENI??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.

} else {
log.Debugf("Tag the newly created eni with arn: %s", arnString)
log.Debugf("Tag the newly created eni: %s", eniID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please rephrase this message to
"Successfully tagged eni: %s", eniID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, makes more sense.

@liwenwu-amazon liwenwu-amazon added this to the v1.1 milestone Jul 11, 2018
* Also introduce two new tags:
  - node.k8s.amazonaws.com/instance_id
  - cluster.k8s.amazonaws.com/name (only tagged if the env var CLUSTER_NAME is present).
Copy link
Contributor

@vsiddharth vsiddharth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants